/**
  ******************************************************************************
  * @file   format.c
  * @author Administrator
  * @since  2024/7/30
  *
  * @brief  Hardware/Peripheral driver of Xxx(Hardware/Simulation-Implemented).
  *
  ******************************************************************************
  */
#include <math.h>
#include "format.h"


int format_percent(struct context *ctx) {
    printf("\n");
    float flash_percent = PERCENT(ctx->rom_used_size, ctx->rom_size);
    float ram_percent = PERCENT(ctx->rw_used_size, ctx->rw_size);

    printf("%13s\t%12s\t%11s\t%9s\n", "Memory Region", "Used Size", "Region Size", "%age Used");
    printf("%13s\t%10d B\t%8d KB\t%8.2f%%\n", "RAM:", ctx->rw_used_size, KB(ctx->rw_size), ram_percent);
    printf("%13s\t%10d B\t%8d KB\t%8.2f%%\n", "FLASH:", ctx->rom_used_size, KB(ctx->rom_size), flash_percent);

    return 0;
}

int format_progress_bar(struct context *ctx) {
    printf("\n");

    printf("Total RW  Size (       RW Data + ZI Data) %15d (%7.2f KB)\n",
           ctx->rw_used_size, KB_F(ctx->rw_used_size));
    printf("Total ROM Size (Code + RW Data + RO Data) %15d (%7.2f KB)\n",
           ctx->rom_used_size, KB_F(ctx->rom_used_size));

    printf("\n[");

    uint8_t per = (uint8_t) ceilf(PERCENT(ctx->rw_used_size, ctx->rw_size));
    for (int i = 0; i < per; ++i) {
        printf("=");
    }
    for (int i = 0; i < 100 - per; ++i) {
        printf("-");
    }
    printf("]%7.2f%%  RAM USED", PERCENT(ctx->rw_used_size, ctx->rw_size));

    printf("\n[");

    per = (uint8_t) ceilf(PERCENT(ctx->rom_used_size, ctx->rom_size));
    for (int i = 0; i < per; ++i) {
        printf("=");
    }
    for (int i = 0; i < 100 - per; ++i) {
        printf("-");
    }
    printf("]%7.2f%%  ROM USED", PERCENT(ctx->rom_used_size, ctx->rom_size));

    return 0;
}

int format_sector(struct context *ctx) {
    // TODO display rom/ram size in sector
    return ERROR_FUNCTION_NOT_SUPPORT;
}